<template>
	<view class="body" @click="goChat">
		<view class="top">
			<up-avatar :src="chatData.data?.friend_info.avatar" shape="circle" size="50"> </up-avatar>
			<view class="right">
				<h3>{{chatData.data?.friend_info.user_name}}</h3>
				<view class="chat">
					<span>{{chatData.data?.last_message}}</span>
				</view>
			</view>
			<view class="time">
				<span>{{replyTime}}</span>
			</view>
		</view>
	</view>
</template>

<script lang="ts" name="user" setup>
	import formatTime from "../common/formatTime.js"
	import chatStore from "../store/modules/chatroom"
	import { reactive, onMounted, ref } from 'vue'
	// let data = reactive({
	// 	src: 'https://tupian.qqw21.com/article/UploadPic/2020-7/202071322581129212.jpg',
	// 	Username: '名字',
	// 	chat: '你好呀，这是我们第一次聊天sssss',
	// 	Time: '2024-12-02'
	// })
	const chatData = defineProps({
		data: Object,
	})
	let replyTime = ref()
	onMounted(() => {
		timechange()

	})
	const goChat = function () {
		uni.navigateTo({
			url: `/pages/chat/chat`
		})
		let chatroom = chatStore()

		chatroom.addChatRoom(chatData.data)
		console.log(chatData.data);
	}


	//时间戳转化
	function timechange() {
		replyTime.value = formatTime(chatData.data?.last_active_time * 1000)

	}
</script>

<style lang="scss" scoped>
	.top {
		position: relative;
		padding: 20upx 40upx 20upx 20upx;

		// box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
		.right {
			top: 10upx;
			left: 120upx;
			position: absolute;
			margin-left: 20upx;
			margin-top: 20upx;

			.chat {
				width: 400upx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap; //文字溢出显示省略号
			}
		}

		.time {
			top: 60upx;
			right: 20upx;
			position: absolute;
			font-size: 23upx;
		}
	}
</style>